package vsvm.gui.forms;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import vsvm.classifier.AbstractTestSet;
import vsvm.graphics.charts.PNROCChart;
import vsvm.graphics.charts.ROCChart;
import vsvm.gui.VSVMInternalFrame;
import vsvm.math.CoreMath;
import vsvm.math.statistics.ROCAnalysis;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class ROCFrame extends VSVMInternalFrame {

	private JPanel jContentPanel  = null;
	private JPanel jNumbersPanel  = null;
	private DefaultTableModel defaultTableModel = null;
	private JTable jNumbersTable  = null;
	
	private ROCAnalysis roc = null;
	private AbstractTestSet testSet = null;
	/**
	 * This method initializes 
	 * 
	 */
	public ROCFrame(AbstractTestSet testSet) {
		super("Receiver Operating Characteristic Curve");
		this.testSet = testSet;
		roc = new ROCAnalysis(testSet);
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        this.setSize(new java.awt.Dimension(456,242));
        this.setContentPane(getJContentPanel());        
			
	}

	/**
	 * This method initializes jContentPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPanel() {
		if (jContentPanel == null) {
			jContentPanel = new JPanel();
			jContentPanel.setLayout(new BorderLayout());			
			ROCChart chart = new ROCChart("ROC Curve for " + this.testSet.getName(), this.roc);
			jContentPanel.add(chart, BorderLayout.CENTER);
			jContentPanel.add(this.getJNumbersPanel(), BorderLayout.SOUTH);			
		}
		return jContentPanel;
	}
	
	private JPanel getJNumbersPanel() {
		if (jNumbersPanel == null) {
			jNumbersPanel = new JPanel();
			jNumbersPanel.setLayout(new BorderLayout());
			jNumbersPanel.add(this.getJNumbersTable(), BorderLayout.CENTER);			
		}
		return this.jNumbersPanel;
	}
	
	private DefaultTableModel getDefaultTableModel() {
		if (defaultTableModel == null) {
			defaultTableModel = new DefaultTableModel();
			defaultTableModel.setColumnCount(2);
			defaultTableModel.setRowCount(3);			
			
			defaultTableModel.setValueAt("Area under curve (AUC)",  0, 0);
			defaultTableModel.setValueAt("W statistic",    1, 0);
			defaultTableModel.setValueAt("Standard Error",  2, 0);
			
			defaultTableModel.setValueAt(roc.getAUC(), 0 , 1);			
			defaultTableModel.setValueAt(roc.getWStatistic(), 1 , 1);
			defaultTableModel.setValueAt(roc.getStandardError(), 2 , 1);
			
		}
		
		return defaultTableModel;
	}
	
	private JTable getJNumbersTable() {
		if (jNumbersTable == null) {
			jNumbersTable = new JTable();
			jNumbersTable.setFont(new java.awt.Font("Courier New", java.awt.Font.PLAIN, 12));
			jNumbersTable.setModel(getDefaultTableModel());
			
		}
		return jNumbersTable;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
